﻿namespace Mozi.Live.SDP
{
    /// <summary>
    /// 会话发布者信息
    /// </summary>
    public class SDPOrigin
    {
        private string netType = "IN";
        private string addressType = "IP4";

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 编号
        /// </summary>
        public long SessionId { get; set; }
        /// <summary>
        /// 会话版本
        /// </summary>
        public long SessionVersion { get; set; }
        /// <summary>
        /// 网络类型
        /// </summary>
        public string NetType { get => netType; set => netType = value; }
        /// <summary>
        /// 地址类型
        /// </summary>
        public string AddressType { get => addressType; set => addressType = value; }
        /// <summary>
        /// 地址
        /// </summary>
        public string Address { get; set; }
        /// <summary>
        /// SDP字符串格式
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{UserName??"-"} {SessionId} {SessionVersion} {NetType} {AddressType} {Address}";
        }
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="desc"></param>
        /// <returns></returns>
        public static SDPOrigin Parse(string desc)
        {
            SDPOrigin ori = new SDPOrigin();
            string[] descs = desc.Split(new char[] { ' ' });
            if (descs.Length >= 6)
            {
                ori.UserName = descs[0];
                ori.SessionId = long.Parse(descs[1]);
                ori.SessionVersion = long.Parse(descs[2]);
                ori.NetType = descs[3];
                ori.AddressType = descs[4];
                ori.Address = descs[5];
            }
            return ori;
        }
    }

}
